<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../../css/common.css" />
		<link rel="stylesheet" type="text/css" href="../../css/my/coupon.css" />
	</head>

	<body>
		<div id="coupon" v-cloak>
			<header class="mui-bar mui-bar-nav">
				<a class="mui-action-back mui-icon mui-icon-arrowleft mui-pull-left"></a>
				<h1 class="mui-title">优惠券</h1>
			</header>
			<div class="ordernav">
				<div :class="{checked:check==0}" @tap="checkTap(0)">未使用</div>
				<div :class="{checked:check==1}" @tap="checkTap(1)">已使用</div>
				<div :class="{checked:check==2}" @tap="checkTap(2)">已过期</div>
			</div>
			<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
				<div class="mui-scroll">

					<div class="coupon_list" v-for="list in list">
						<div class="coupon_img">
							<img src="../../images/youhui.png" />
							<div class="coupon_sum">
								<div>￥{{list.offPrice}}</div>
								<div>满{{list.fullPrice}}可用</div>
							</div>
						</div>
						<div class="coupon_data">
							<div>{{list.couponName}}</div>
							<div>使用平台:全平台</div>
							<div>有效期:{{list.endDateStr}}</div>
						</div>
						<div class="coupon_use" @tap="immediately">
							立即使用
						</div>
					</div>
					<div></div>
				</div>
			</div>
			<div class="nocoupon">
				你暂时还没有可用的优惠券
			</div>
			<div class="gocoupon" @tap="clsOpen">
				<button type="button" class="mui-btn mui-btn-danger">去领券中心</button>
			</div>
		</div>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/libs/zepto.js"></script>
		<script src="../../js/libs/vue.js"></script>
		<script src="../../js/common.js"></script>
		<script type="text/javascript">
			mui.init({
				pullRefresh: {
					container: '#pullrefresh',
					up: {
						auto: true,
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
			})

			var coupon = new Vue({
				el: '#coupon',
				data: {
					imgCommonUrl: common.imageUrl,
					pageNum: 1,
					check: 0,
					list: []
				},
				methods: {
					checkTap: function(index) {
						if(this.check == index) {
							return
						}
						this.check = index
						mui('#pullrefresh').pullRefresh().refresh(true);
						coupon.list = []
						coupon.pageNum = 1
						mui('#pullrefresh').pullRefresh().pullupLoading();
						mui('#pullrefresh').pullRefresh().scrollTo(0, 0, 0.1);
					},
					clsOpen: function() {
						common.open('coiponcenter.html', '../my/coiponcenter.html')
					},
					immediately: function() {
						var list = plus.webview.getWebviewById("ylindex.html")
						mui.fire(list, 'gohome');
						var wvs, self, launch;
						wvs = plus.webview.all();
						self = plus.webview.currentWebview();
						launch = plus.webview.getLaunchWebview();
						for(var i = 0, len = wvs.length; i < len; i++) {
							if(wvs[i].getURL() == launch.getURL() || wvs[i].id == 'ylindex.html' || wvs[i].id == 'home.html' || wvs[i].id == 'classify.html' || wvs[i].id == 'special.html' || wvs[i].id == 'shopping.html' || wvs[i].id == 'my.html' || wvs[i].id == '../special/specialregion.html') {
								continue;
							}
							wvs[i].close();
						}
					}
				}
			})

			function pullupRefresh() {
				$('.mui-pull-bottom-pocket').css('display', 'block !important')
				$(".nocoupon").hide()
				var urls = ['/coupon/getList', '/coupon/getListUsed', '/coupon/getListOverdue']
				common.ajax(urls[coupon.check], {
					curPageNO: coupon.pageNum++,
					couPro: 'shop'
				}, function(data) {
					if(data.code == 1) {
						console.log(data.data)
						if(coupon.pageNum > data.data.pageCount) {
							mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
						} else {
							mui('#pullrefresh').pullRefresh().endPullupToRefresh();
						}
						coupon.list = coupon.list.concat(data.data.list)
						if(coupon.list.length <= 0) {
							$('.mui-pull-bottom-pocket').css('display', 'none !important')
							$(".nocoupon").show()
						} else {
							$('.mui-pull-bottom-pocket').css('display', 'block !important')
							$(".nocoupon").hide()
						}
					} else {
						mui('#pullrefresh').pullRefresh().endPullupToRefresh();
						if(data.resultMsg) {
							mui.toast(data.resultMsg)
						}
					}
				}, true, 'get')
			}
			document.addEventListener('reloads', function() {
				mui('#pullrefresh').pullRefresh().refresh(true);
				coupon.list = []
				coupon.pageNum = 1
				mui('#pullrefresh').pullRefresh().pullupLoading();
				mui('#pullrefresh').pullRefresh().scrollTo(0, 0, 0.1);
			})
		</script>
	</body>

</html>